package com.baidu.hao.controller;

import com.baidu.hao.bean.User;
import com.baidu.hao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public  String delete(@PathVariable("id") Integer id){
        //执行删除操作
        System.out.println("id = " + id);
        userService.delete(id);
        return "redirect:/route";
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public  String updateOrder(User user, HttpServletRequest request){
        //执行修改操作
        String updateImgId = request.getParameter("update_select");
        System.out.println("id = " + user.getId());
        userService.update(user,updateImgId);
        return "redirect:/route";
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public  String save(User user, HttpServletRequest request){
        //执行更新操作
        String addImgId = request.getParameter("add_select");
        userService.add(user,addImgId);
        return "redirect:/route";
    }

}
